package com.jsoup.controller.user;

import com.jsoup.bean.Stayword;
import com.jsoup.service.StaywordService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/userStayWord")
public class UserStayWordController {

    @Resource
    private StaywordService staywordService;

    /**
     * 添加留言
     *
     * @param stayword
     * @return
     */
    @RequestMapping("/addStayWord")
    @RequiresRoles("user")
    @ResponseBody
    public Object addStayWord(Stayword stayword) {
        Map<Object, Object> map = new HashMap<>();
        stayword.setStaywordState(0);
        stayword.setStaywordDate(new Timestamp(System.currentTimeMillis()));
        int count = staywordService.insertSelective(stayword);
        if (count > 0) {
            map.put("result", 200);
        }
        return map;
    }
}
